package com.txsj.scan.base;

import android.content.Context;

import com.txsj.scan.MyApplication;

import io.reactivex.disposables.CompositeDisposable;

public abstract class BasePresenter<V extends IView> {
    protected V view;
    protected CompositeDisposable compositeDisposable = new CompositeDisposable();

    public BasePresenter(V view) {
        this.view = view;
        initModel();
    }

    protected abstract void initModel();

    //解决内存泄漏
    void onDestroy() {
        view = null;
        compositeDisposable.clear();
    }


    protected Context context() {
        if (view != null && view.context() != null) {
            return view.context();
        } else {
            return MyApplication.getInstance();
        }
    }
}
